const router = require("express").Router();
const mysqlhandle = require("../routehandles/mysqlhandle");

//新建任务图片文件夹
function createFolder(fname){
    var fldr = "";
	var fso = new ActiveXObject("Scripting.FileSystemObject");
    fldr = "../public/picture/"+fname
	if(!fso.FolderExists(fldr)){     //判断文件夹是否存在，不存在就创建
		fso.CreateFolder (fldr);
	}
    return fldr
}

//接受任务函数
router.post('/accepttask',async (req,res) => {
    const params = req.body;
    // var xx = await mysqlhandle.sUAPTable(params.username);
    // nickname = xx[0]["nickname"];
    // var yy = await mysqlhandle.sAccessTable()   //查询编号
    // var tasknum = yy.length+1;
    // var picurl = "/"
    //var picurl = createFolder(String(params.username)+String(tasknum))
    //console.log(picurl)
    // var begintime = new Date().toLocaleDateString().split('/').map(item=>{if (item<10){return '0'+ item}else {return item}}).join('-')
    // console.log("begintime:"+begintime)

    await mysqlhandle.iAccessTable(params.username,params.num);  //往AccessTable表中插入
    res.json({msg:'创建任务成功'})
})

//结束任务函数
router.post('/finishtask',(req,res) => {
    const params = req.body;
    mysqlhandle.uPublishTable('status','已结束',params.username,params.tasknum);
})

module.exports = router

